package com.ykt.controller;

import com.jfinal.ext.route.ControllerBind;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;
import com.ykt.model.Admin;

@ControllerBind(controllerKey="/admin")
public class AdminController extends BaseController<Admin> {
	
	public AdminController() {
		super(Admin.class);
	}

	@Override
	protected void otherSave(Model<Admin> m) {
		
		Integer admin_id = m.getInt("id");
		String []sidList=getParaValues("sids");
		String sids="";
		Db.update("delete from admin_role where admin_id=?",admin_id);//先删除所有权限
		if(sidList!=null){
			for(String id_str : sidList) {
				sids+=id_str+",";
				Integer sid = Integer.parseInt(id_str);
				Db.update("insert into admin_role(admin_id,role_id,created_time) values(?,?,now())",admin_id,sid);
			}
			if(sids.length()>1)  sids=sids.substring(0, sids.length()-1);
		}
		m.set("role_ids", sids);
		m.update();
	}
	
}
